package com.carkeeper.serve.controller;

import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.carkeeper.pojo.Serve;
import com.carkeeper.pojo.ServeDetail;
import com.carkeeper.serve.service.ServeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/serve")
public class ServeController {

    @Autowired
    private ServeService serveService;

    /**
     * 分页条件查询
     * @param map
     * @return
     */
    @ApiOperation("分页条件查询")
    @PostMapping("/findByCondition")
    public Result<PageInfo<Serve>> findByCondition(@RequestBody Map map){
        PageInfo<Serve> userBillInfo = serveService.findByCondition(map);
        return new Result<>(true, StatusCode.OK,"",userBillInfo);
    }

    /**
     * 服务分类展示列表
     * @return
     */
    @ApiOperation("服务分类展示列表")
    @GetMapping("/findByType2")
    public Result<List> findByType2(){
        List list = serveService.findByType2();
        return new Result<>(true,StatusCode.OK,"",list);
    }

    /**
     * 详细信息查询
     * @param id
     * @return
     */
    @ApiOperation("详细信息查询")
    @GetMapping("/findByDateil/{id}")
    public Result<ServeDetail> findByDateil(@PathVariable("id") String id){
        ServeDetail serveDetail = serveService.findByDateil(id);
        return new Result<>(true,StatusCode.OK,"",serveDetail);
    }

    /**
     * 下架
     * @param id
     * @return
     */
    @ApiOperation("下架")
    @GetMapping("/down/{id}")
    public Result down(@PathVariable("id") String id){
        serveService.down(id);
        return new Result(true,StatusCode.OK,"");
    }

}
